"""
@name : 02.元组
@author : wenyao
@projectname: 空气质量.py
"""

#元组
#有序项目集合
#可以存放任何类型对象
#不可变数据类型


#当元组中只有一个元素的时候，需要在元素后面加逗号，区分这个括号是结合运算符还是元组
# >>> a = ()
# >>> type(a)
# <class 'tuple'>
# >>> a = (1)
# >>> type(a)
# <class 'int'>
# >>> a = (1,)
# >>> type(a)
# <class 'tuple'>
# >>> a = tuple()
# >>> str(10)
# '10'
# >>> int("2")
# 2
# >>> list("abc")
# ['a', 'b', 'c']
# >>> tuple("abc")
# ('a', 'b', 'c')
# >>> list(10)
# Traceback (most recent call last):
#   File "<stdin>", line 1, in <module>
# TypeError: 'int' object is not iterable

#元组一旦被定义，就不能修改
#元组中如果包含列表， 列表中的值是可以被修改
# >>> t1 = (1,2,3,["a","b"],1.1, print)
# >>> t1[2]
# 3
# >>> t1[-5]
# 2
# >>> t1[2]=0
# Traceback (most recent call last):
#   File "<stdin>", line 1, in <module>
# TypeError: 'tuple' object does not support item assignment
# >>> t[3]
# Traceback (most recent call last):
#   File "<stdin>", line 1, in <module>
# NameError: name 't' is not defined
# >>> t1[3]
# ['a', 'b']
# >>> t1[3].append("c")
# >>> t1
# (1, 2, 3, ['a', 'b', 'c'], 1.1, <built-in function print>)
# >>> t1[3]="y"
# Traceback (most recent call last):
#   File "<stdin>", line 1, in <module>
# TypeError: 'tuple' object does not support item assignment

#列表与元组最大的区别就是
#列表是可变数据类型， 元组是不可变数据类型

# >>> a,b = (1,2)
# >>> a
# 1
# >>> b
# 2
# >>> a,b = [1,2]
# >>> a
# 1
# >>> b
# 2
# >>> a,b,c = [1,2]
# Traceback (most recent call last):
#   File "<stdin>", line 1, in <module>
# ValueError: not enough values to unpack (expected 3, got 2)
# >>> a,b,c = [1,2,3]
# >>> a = [1,2,3]
# >>> a
# [1, 2, 3]


# print("欢迎使用用户检测系统")
# lst=[('root','123456'),('admin','admin')]
# account=input("请输入账号名")
# password=input("请输入密码")
# count=0
# for i in lst:
#     count+=1
#     if account == i[0] and password == i[1]:
#         print("欢迎登入到该系统！！")
#         break
#     if count == len(lst):
#         print("账号或密码错误，请再次输入！！")


# users = [("root","123456"),("admin","admin")]
#
# while True:
#     print("欢迎使用用户检测系统")
#     name = input("请输入你的用户名：")
#     password = input("请输入你的密码")
#
#     user = (name,password)
#     if user not in users:
#         print("\033[31m用户名或者密码错误，请重新输入!\033[0m")
#     else:
#         print("欢迎登录天网系统！")
#         break

